﻿using System.Collections.Generic;
using Xunit;
using YAPL.Language.Ast;

namespace YAPL.Test.YAPL.Language.Ast {

	public class FunctionDefExpressionTest {
		[Fact]
		public void NodeEqualsShouldWorkCorrectly() {
			var paramList1 = new List<ParameterExpression>();
			var paramList2 = new List<ParameterExpression>();
			var paramList3 = new List<ParameterExpression>();
			var param1 = Expressions.Parameter(Expressions.Variable("d"), Expressions.StringLiteral("hello"));
			var param2 = Expressions.Parameter(Expressions.Variable("b"), Expressions.StringLiteral("hello2"));

			paramList1.Add(param1);

			paramList2.Add(param1);
			paramList2.Add(param2);

			paramList3.Add(param1);
			var exprList1 = new List<Expression>();
			var exprList2 = new List<Expression>();

			exprList1.Add(Expressions.Assignment(Expressions.Variable("a"), Expressions.StringLiteral("hello1")));
			exprList1.Add(Expressions.ReturnStatement(Expressions.Variable("a")));

			exprList2.Add(Expressions.ReturnStatement(Expressions.StringLiteral("hello2")));

			var codeblock1 = Expressions.CodeBlock(exprList1);
			var codeblock2 = Expressions.CodeBlock(exprList2);

			var funcDef1 = Expressions.Function("func1", paramList1, codeblock1);
			var funcDef2 = Expressions.Function("func2", paramList2, codeblock2);
			var funcDef3 = Expressions.Function("func1", paramList3, codeblock2);

			Assert.False(funcDef1.NodeEquals(null));
			Assert.False(funcDef1.NodeEquals(Expressions.StringLiteral("dd")));
			Assert.False(funcDef1.NodeEquals(funcDef2));
			Assert.True(funcDef1.NodeEquals(funcDef1));
			Assert.True(funcDef1.NodeEquals(funcDef3));
		}
	}
}
